package com.jyxd.web.jobhandler;

import com.jyxd.web.service.assessment.basic.VitalSignMergeService;
import com.jyxd.web.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import tech.powerjob.official.processors.util.CommonUtils;
import tech.powerjob.worker.core.processor.ProcessResult;
import tech.powerjob.worker.core.processor.TaskContext;
import tech.powerjob.worker.core.processor.sdk.BasicProcessor;
import tech.powerjob.worker.log.OmsLogger;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Component
@Slf4j
public class CustomSyncNurseRecordForm implements BasicProcessor {

    private final VitalSignMergeService vitalSignMergeService;

    public CustomSyncNurseRecordForm(VitalSignMergeService vitalSignMergeService) {
        this.vitalSignMergeService = vitalSignMergeService;
    }

    @Override
    public ProcessResult process(TaskContext context) throws Exception {

        final OmsLogger omsLogger = context.getOmsLogger();
        final String patientId = CommonUtils.parseParams(context);
        if (StringUtils.isEmpty(patientId)) {
            log.info("患者Id为空,跳过任务");
            omsLogger.info("患者Id为空,跳过自定义同步任务");
        } else {
            Map<String, String> map = new HashMap<>();
            map.put("time", DateUtil.yyyyMMddHHmmssSdfToString(new Date()));
            map.put("patientId", patientId);
            vitalSignMergeService.syncVitalSignMerge(map, null);
        }
        return new ProcessResult(true);
    }
}
